<?php
namespace App\Http\Controllers;

use App\Http\Model\Hint;
use App\Http\Services\MsgServices;
use App\Http\Services\TogetherGameService;
use App\Http\Services\UserServices;
use Illuminate\Http\Request;
use App\Lib\Response;

class TogetherGameController extends Controller
{
    protected $togetherGameService; //一起玩服务
    protected $msg_service;
    protected $services_users;

    public function __construct()
    {
        $this->togetherGameService = new TogetherGameService();
        $this->msg_service = new MsgServices();
        $this->services_users = new UserServices();
    }

    //获取一起玩总开关
    public function getGameOpen(){
        $userInfo = $this->services_users->get_current_user();
        if(empty($userInfo)){
            Response::returnResult(Hint::LOGIN_OUT);
        }
        //一起玩开关权限
        $togetherGameOpen = $this->togetherGameService->togetherGamePermission($userInfo['user_id']);
        //今日是否签到
        $signStatus = $this->togetherGameService->getTodaySign($userInfo['user_id']);
        $data['together_game_open'] = $togetherGameOpen;

        $data['jd_store_url'] = ''; //金豆商店链接
        $data['today_sign'] = $signStatus;//今日签到状态
        Response::returnResult(Hint::SUCCESS,$data);
    }

    //获取一起玩游戏列表
    public function getGameList(Request $request){
        $user_id = $request->get('user_id',0);
        if(empty($user_id)){
            Response::returnResult(Hint::PARAM_ERROR);
        }
        $list = $this->togetherGameService->getGameList($user_id);
        Response::returnResult(Hint::SUCCESS,$list);
    }

    //一起玩签到列表
    public function gameSignList(Request $request){
        $user_id = $request->get('user_id',0);
        if(empty($user_id)){
            Response::returnResult(Hint::PARAM_ERROR);
        }
        $list = $this->togetherGameService->getGameSignList($user_id);
        Response::returnResult(Hint::SUCCESS,$list);
    }

    //一起玩用户签到
    public function gameSignDailySet(Request $request){
        $user_id = $request->post('user_id',0);//用户id
        $sign_id = $request->post('id',0);//签到id
        if(empty($user_id) || empty($sign_id)){
            Response::returnResult(Hint::PARAM_ERROR); 
        }
        $returnData = $this->togetherGameService->dailyGameSetSign($user_id,$sign_id);
        if($returnData['code'] != Hint::SUCCESS){
            Response::returnResult(Hint::ERR_NORMAL,[],$returnData['msg']);
        }
        Response::returnResult(Hint::SUCCESS,['tag'=>$returnData['msg']]);
    }

    //一起玩游戏滚动公告
    public function getGameNotice(){
        $notice = $this->togetherGameService->getGameNotice();
        Response::returnResult(Hint::SUCCESS,$notice);
    }
}